#!/bin/bash
set -eo pipefail
shopt -s nullglob

# logging functions
docker_log() {
    local type="$1"; shift
    printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "$type" "$*"
}
docker_note() {
    docker_log Note "$@"
}
docker_warn() {
    docker_log Warn "$@" >&2
}
docker_error() {
    docker_log ERROR "$@" >&2
    exit 1
}

docker_process_init_files() {
    echo
    local f
    for f; do
        case "$f" in
            *.sh)
                if [ -x "$f" ]; then
                    docker_note "$0: running $f"
                    sh "$f"
                else
                    docker_note "$0: sourcing $f"
                    . "$f"
                fi
                ;;
            *)        docker_warn "$0: ignoring $f" ;;
        esac
        echo
    done
}

docker_process_init_files /docker-entrypoint-initweb.d/*

supervisord -c /etc/supervisor/supervisord.conf -n
